{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "8DFZRnmEHWz_"
   },
   "source": [
    "# Create Taylor Swift Embeddings Data\n",
    "\n",
    "Use this colab to analyze trends in Taylor Swift's song lyrics using [Phoenix OSS](https://github.com/Arize-ai/phoenix). Download the Kaggle dataset [here](https://www.kaggle.com/datasets/PromptCloudHQ/taylor-swift-song-lyrics-from-all-the-albums?select=taylor_swift_lyrics.csv)."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "!pip install arize-phoenix"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import phoenix as px"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from google.colab import files\n",
    "\n",
    "uploaded = files.upload()  # upload CSV from Kaggle"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "df = pd.read_csv(\"taylor_swift_lyrics.csv\", encoding=\"ISO-8859-1\")\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "!pip install arize[\"AutoEmbeddings\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from arize.pandas.embeddings import EmbeddingGenerator, UseCases\n",
    "\n",
    "df = df.reset_index(drop=True)\n",
    "\n",
    "generator = EmbeddingGenerator.from_use_case(\n",
    "    use_case=UseCases.NLP.SEQUENCE_CLASSIFICATION,\n",
    "    model_name=\"distilbert-base-uncased\",\n",
    "    tokenizer_max_length=512,\n",
    "    batch_size=100,\n",
    ")\n",
    "df[\"lyric_vector\"] = generator.generate_embeddings(text_col=df[\"lyric\"])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "schema = px.Schema(\n",
    "    embedding_feature_column_names={\n",
    "        \"taylors_embedding\": px.EmbeddingColumnNames(\n",
    "            vector_column_name=\"lyric_vector\", raw_data_column_name=\"lyric\"\n",
    "        )\n",
    "    },\n",
    "    feature_column_names=[\"year\", \"album\", \"track_title\"],\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "px.launch_app(px.Dataset(df, schema))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "px.active_session().view()"
   ]
  }
 ],
 "metadata": {
  "language_info": {
   "name": "python"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
